package com.example.JcGQS.controller;

import com.example.JcGQS.pojo.dto.*;
import com.example.JcGQS.response.ResultUtil;
import com.example.JcGQS.service.PurchaseService;
import com.example.JcGQS.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jws.soap.SOAPBinding;
import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.RespectBinding;

/**
 *  采购信息控制器
 * @author 末日
 * @data 2023/11/10
 */
@RestController
@RequestMapping("/GQS/purchase")
public class PurchaseController {

    @Autowired
    PurchaseService purchaseService;
    /**
     * 新增采购信息
     * @return
     */
    @PostMapping("insert")
    public void insertPurchase(@RequestBody InsertPurchaseDTO insertPurchaseDTO, HttpServletRequest request){
        String token = request.getHeader("Authorization");
        Integer userId = JwtUtil.getUserIdByJWT(token);
        purchaseService.insertPurchase(insertPurchaseDTO,userId);
    }
    /**
     * 批量新增采购信息
     * @return
     */
    @PostMapping("list/insert")
    public void insertPurchaseList(@RequestBody InsertPurchaseListDTO insertPurchaseListDTO, HttpServletRequest request){
        String token = request.getHeader("Authorization");
        Integer userId = JwtUtil.getUserIdByJWT(token);
        purchaseService.insertPurchaseList(insertPurchaseListDTO,userId);
    }
    /**
     * 删除采购信息
     * @return
     */
    @PostMapping("delete")
    public void deletePurchase(@RequestBody PurchaseId purchaseId, HttpServletRequest request){
        String token = request.getHeader("Authorization");
        purchaseService.deletePurchase(purchaseId,token);
    }

    /**
     * 修改采购信息
     * @return
     */
    @PostMapping("update")
    public void updatePurchase(@RequestBody UpdatePurchaseDTO updatePurchaseDTO, HttpServletRequest request){
        String token = request.getHeader("Authorization");
        purchaseService.updatePurchase(updatePurchaseDTO,token);

    }

    @PostMapping("/a")
    public void aVoid(){
        purchaseService.aVoid();
    }
    /**
     * 修改采购状态
     * @return
     */
    @PostMapping("update/state")
    public void updatePurchaseState(@RequestBody UpdatePurchaseStateDTO updatePurchaseStateDTO, HttpServletRequest request){
        String token = request.getHeader("Authorization");
        purchaseService.updatePurchaseState(updatePurchaseStateDTO,token);


    }
    /**
     * 获取采购信息类型列表
     * @return
     */
    @PostMapping("list")
    public void updatePurchaseState(@RequestBody PageDTO pageDTO, HttpServletRequest request){
        String token = request.getHeader("Authorization");
        purchaseService.PurchaseList(pageDTO,token);
    }
}
